/**
 * @class   wosh::application::WoshRemoteWindow
 * @brief   
 *
 * @version $Id: WoshRemoteWindow.h 2618 2010-06-04 09:48:15Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Apps_WoshTrayServer_WoshRemoteWindow_H__
 #define __WOSH_Apps_WoshTrayServer_WoshRemoteWindow_H__

 #include <woshDefs.h>
 #include <core/BusConnector.h>

 #include <framework/gui/GuiUtilities.h>
 #include <framework/gui/components/WidgetQMenu.h>

 #include <bundles/services/DesktopNotifier/DesktopNotifierBundle.h>

 #include <QtGui/QMainWindow>
 #include <QSystemTrayIcon>
 #include <QSignalMapper>
 #include <QLabel>


using namespace wosh;
using namespace wosh::gui;
using namespace wosh::services;

namespace Ui {
 class WoshRemoteWindow;
}
namespace wosh {
  namespace gui {
   class FormBuildingManager;
  };
};

namespace wosh {
  namespace application {

#define _APPLICATION_WOSH_REMOTE_NAME		"WOSH Remote"
#define _APPLICATION_WOSH_REMOTE_VERSION	"0.72"


class WoshRemoteWindow :	public QMainWindow,
							public virtual IBusListener,
							public virtual IReflection
 {
	Q_OBJECT

	WOSH_CLASSNAME(wosh::application::WoshRemoteWindow)
	WOSH_CLASS_ABSTRACT(false)


	public:
		WoshRemoteWindow( QWidget *parent = NULL );

		virtual ~WoshRemoteWindow();

		void init();

		static WoshRemoteWindow* getInstance()		{ return WoshRemoteWindow::instance; }

	public:
		void setVisible(bool visible);

	protected:
		void changeEvent(QEvent *e);
		void closeEvent(QCloseEvent *event);


	public:
		void busMessage( const Message& message, const Bus* source );

	public slots:
		void create_GUI( const string& name, const string& type, const URI& uri, const QStringList& interfaces = QStringList() );

		void quitWosh();

/** @name configuration methods
 * @{
 ******************************************************************************/
 	protected:
		void readSettings();
		void writeSettings();

	    void loadStyleSheet(const QString &sheetName);
		void loadLanguage(const QString& language);

		void refreshInfo();

//@}
/** @name menu handlers
 * @{
 ******************************************************************************/
 	protected slots:

		void menu_StaticItem_triggered( QAction* action );
		void menu_CreateGUI_triggeredItem( WidgetQMenuItem * actionItem );
		void menuWOSH_Kernel_triggeredItem( WidgetQMenuItem* actionItem );

		void createTrayIcon();
		void createMenus();
		void configureStatusBar();

		void updateDynamicMenus();
		void updateStatusBar();

 	protected slots:

		void on_styleCombo_activated(const QString &styleName);
		void on_styleSheetCombo_activated(const QString &sheetName);

 	protected slots:

		void chkDesktopNotifier_clicked();
		void chkTraySettingsSmartMenu_clicked();

		void response_DesktopNotifier( int state );

//@}
/** @name Tray Icon methods
 * @{
 ******************************************************************************/
	private slots:
		void iconActivated(QSystemTrayIcon::ActivationReason reason);
		void showMessage( const QString& title, const QString& message, long timeout, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information );

	public:
		QSystemTrayIcon* getTrayIcon()		{ return this->trayIcon; }
		void setDesktopNotifierBundle(DesktopNotifierBundle* ptr )
											{ this->desktopNotifierBundle = ptr; }

//@}
/** @name Tray Icon vars
 * @{
 ******************************************************************************/
	protected:
		QSystemTrayIcon *trayIcon;
		QMenu* menuTrayMenu;
//		QAction lastCommand;

		DesktopNotifierBundle* desktopNotifierBundle;

		bool reallyExiting;
//@}

	signals:
		void s_DesktopNotifier(int state);
		void s_showMessage( const QString& title, const QString& message, long timeout, QSystemTrayIcon::MessageIcon icon );

	private:
		Ui::WoshRemoteWindow *m_ui;

		static WoshRemoteWindow* instance;

	protected:
		// static forms
		FormBuildingManager* formBuildingManager;

	protected:
		// status bar items
		QLabel* statusUserAtKernelLbl;

	protected:
		BusConnector BusCore;
		BusConnector BusGui;

		URI myUri;
		LogContext Log;


}; // class def

  }; // namespace application
}; // namespace wosh

#endif //__WOSH_Apps_WoshTrayServer_WoshRemoteWindow_H__
